/**
 * 评查小组选择器（单选）
 */
var PingchaGroupSelector = {

	/**
	 * callbackOrConf 回调函数或配置选项，若为map类型，则表示为配置选项
	 */
	getView : function(callbackOrConf, selval) {
		if (typeof(callbackOrConf) == 'object') {
			this.scope = callbackOrConf.scope || this;
			this.callback = callbackOrConf.callback;
		} else {
			this.scope = this;
			this.callback = callbackOrConf;
		}
		var panel = this.initPanel(selval);

		this.win = new Ext.Window({
					title : '选择评查小组',
					iconCls : 'menu-template',
					width : 700,
					minWidth : 700,
					height : 480,
					minHeight : 480,
					layout : 'fit',
					border : false,
					maximizable : true,
					modal : true,
					items : [panel],
					buttonAlign : 'center',
					buttons : [{
								text : '确认',
								iconCls : 'btn-ok',
								scope : this,
								handler : this.submit
							}, {
								text : '关闭',
								iconCls : 'btn-cancel',
								scope : this,
								handler : this.close
							}]
				});
		return this.win;
	},

	/**
	 * 组件初始化
	 */
	initPanel : function(selval) {
		this.searchPanel = new KE.SearchPanel({
					region : 'north',
					items : [{
								text : '小组名称'
							}, {
								width : 120,
								name : 'Q_LIKES_name',
								xtype : "textfield"
							}, {
								xtype : 'button',
								text : '查询',
								scope : this,
								iconCls : 'btn-search',
								handler : this.search
							}, {
								xtype : 'button',
								text : '清空',
								scope : this,
								iconCls : 'reset',
								handler : this.reset
							}]
				});
		this.gridPanel = new KE.GridPanel({
					title : '评查小组列表',
					region : 'center',
					height : 380,
					isShowTbar : false,
					singleSelect : true,
					autoWidth : true,
					url : __ctxPath + '/pingcha/listPingchaGroup.do',
					fields : ['oid', 'name', 'master', 'info'],
					style : 'padding:6px;background-color: white',
					defaults : {
						menuDisabled : true
					},
					columns : [{
								dataIndex : 'oid',
								hidden : true
							}, {
								text : '小组名称',
								dataIndex : 'name'
							}, {
								text : '负责人',
								dataIndex : 'master'
							}, {
								text : '成员信息',
								dataIndex : 'info'
							}]
				});
		// 根据传入值，选中GridPanel
		Ext.defer(function() {
					if (selval) {
						var model = this.gridPanel.getSelectionModel();
						this.gridPanel.getStore().each(function(rec) {
									if (rec.data.oid == selval) {
										model.select([rec]);
										return;
									}
								});
					}
				}, 200, this);
				
		var panel = new Ext.Panel({
					layout : 'border',
					anchor : '96%,96%',
					items : [this.searchPanel, this.gridPanel]
				});
		return panel;
	}, // init

	// //////////////###方法###///////////////////////
	// 确定，提交
	submit : function() {
		var id = '';
		var name = '';
		var rows = this.gridPanel.getSelectionModel().getSelection();
		if (rows.length > 0) {
			id = rows[0].data.oid;
			name = rows[0].data.name;
		}
		if (this.callback != null) {
			this.callback.call(this.scope, id, name);
		}
		this.win.close();
	},
	// 关闭当前窗口
	close : function() {
		this.win.close();
	},
	// 重置查询表单
	reset : function() {
		this.searchPanel.getForm().reset();
	},
	// 按条件搜索
	search : function() {
		$search({
					searchPanel : this.searchPanel,
					gridPanel : this.gridPanel
				});
	}
};
